<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
      <el-form-item label="姓名" prop="name">
        <el-input
            v-model="queryParams.name"
            placeholder="姓名"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="cardno">
        <el-input
            v-model="queryParams.cardno"
            placeholder="证件号码"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button type="primary" v-if="false" icon="Plus" @click="handleAdd" v-hasPermi="['by:order:add']">添加
        </el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="orderList">
      <el-table-column label="联系人" align="center" prop="lxr"/>
      <el-table-column label="联系方式" align="center" prop="phone"/>
      <el-table-column label="科目" align="center" prop="km"/>
      <el-table-column label="时间" align="center" prop="time"/>
      <el-table-column label="状态" align="center" prop="status" :formatter="showStatus"/>
      <el-table-column label="详细地址" align="center" prop="address"/>
      <el-table-column label="创建时间" align="center" prop="addtime" width="180"/>
      <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" @click="handleDetail(scope.row)" v-hasPermi="['by:order:query']"></el-button>
<!--          <el-button link type="primary" @click="handleUpdate(scope.row)" v-hasPermi="['by:order:query']">修改</el-button>-->
<!--          <el-button link type="primary" @click="handleDelete(scope.row)" v-hasPermi="['by:order:query']">取消</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 订单详情 -->
    <el-dialog title="订单详情" v-model="openDetailDialog" width="700px" append-to-body>
      <el-form :model="formDetail" label-width="100px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人：">{{ formDetail.lxr }}</el-form-item>
            <el-form-item label="联系方式：">{{ formDetail.phone}}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="科目：">{{ formDetail.km }}</el-form-item>
            <el-form-item label="时间：">{{ formDetail.time }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="详细地址：">{{ formDetail.address }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="--">--</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="帮手姓名：">{{ bsDetail.name }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="院校：">{{ bsDetail.school }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专业：">{{ bsDetail.subject }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码：">{{ bsDetail.cardno }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系方式：">{{ bsDetail.mobile }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="--">--</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="定金：">{{ formDetail.dprice }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手续费：">{{ formDetail.orderprice }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开始时间：">{{ formDetail.starttime }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束时间：">{{ formDetail.endtime }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="订单金额：">{{ formDetail.allprice }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="应付(后)：">{{ formDetail.payprice }}</el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建时间：">{{ parseTime(formDetail.addtime) }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeDetailDialog">关 闭</el-button>
        </div>
      </template>
    </el-dialog>

  </div>
</template>

<script setup>
  import { listOrder, getOrder, getOrderInfo } from "@/api/bydll/order";

  const showSearch = ref(true);
  const orderList = ref([]);
  const open = ref(false);
  const openDetailDialog = ref(false);
  const title = ref("");
  const loading = ref(true);
  const total = ref(0);
  const ids = ref([]);
  const imageUrl = ref('');
  const data = reactive({
    form: {},
    formDetail: {},
    bsDetail:{},
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      name: undefined
    }
  });
  const {queryParams, form, formDetail, bsDetail} = toRefs(data);

  function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
  }

  function getList() {
    loading.value = true;
    listOrder(queryParams.value).then(response => {
      orderList.value = response.rows;
      total.value = response.total;
      loading.value = false;
    });
  }

  /** 订单详情 */
  function handleDetail(row) {
    const orderId = row.id;
    let param = {"id":orderId};
    getOrderInfo(param).then(response => {
      // console.log(JSON.stringify(response));
      formDetail.value = response.data.order;
      bsDetail.value = response.data.bs;
      openDetailDialog.value = true;
    });
  }

  /** 关闭对话详情对话框 */
  function closeDetailDialog() {
    openDetailDialog.value = false
    formDetail.value = {}
  }

  function showStatus(row, column){
    if(row.status === '1'){
      return "待支付";
    }else if(row.status === '2'){
      return "待付定金";
    }else if(row.status === '3'){
      return "待上门";
    }else if(row.status === '4'){
      return "服务中";
    }else if(row.status === '5'){
      return "待付尾款";
    }else if(row.status === '6'){
      return "完成";
    }else if(row.status === '7'){
      return "订单取消";
    }
    return "未知状态";
  }

  getList();
</script>
